/**
 * Copyright &copy; 2012-2016 <a href="https://www.kaaction.com">KAA</a> All rights reserved All rights reserved.
 */
package com.kaaction.modules.ka.entity;

import org.hibernate.validator.constraints.Length;

import java.text.DecimalFormat;

import javax.validation.constraints.NotNull;

import com.kaaction.common.persistence.DataEntity;
import com.kaaction.common.utils.excel.annotation.ExcelField;

/**
 * 财务报表Entity
 * @author ZengBiao
 * @version 2017-06-23
 */
public class KaFinance extends DataEntity<KaFinance> {
	
	private static final long serialVersionUID = 1L;
	private String year;		// 年份,yyyy格式
	private String month;		// 月份，MM格式
	private KaSupplier supply;		// 供应商编号
	private KaCategory kaCategory;		// 分类编号
	private String unit;		// 单位
	private Double beginNum;		// 期初库存
	private Double beginPrice;		// 期初单价
	private Double beginCost;		// 期初成本
	private Double checkinNum;		// 入库数量
	private Double badNum;		// 残次品数量
	private Double checkinPrice;		// 入库单价
	private Double checkinCost;		// 入库成本
	private Double checkoutNum;		// 出库数量
	private Double checkoutPrice;		// 出库单价
	private Double checkoutCost;		// 出库成本
	private Double endNum;		// 期末库存数量
	private Double endPrice;		// 期末库存单价
	private Double endCost;		// 期末成本
	private String code;		// 货号
	private String note;		// 备注
	private Integer sort;		// 排序
	
	public KaFinance() {
		super();
	}

	public KaFinance(String id){
		super(id);
	}

	@Length(min=1, max=4, message="年份,yyyy格式长度必须介于 1 和 4 之间")
	public String getYear() {
		return year;
	}

	public void setYear(String year) {
		this.year = year;
	}
	
	@Length(min=1, max=2, message="月份，MM格式长度必须介于 1 和 2 之间")
	public String getMonth() {
		return month;
	}

	public void setMonth(String month) {
		this.month = month;
	}
	
	public KaSupplier getSupply() {
		return supply;
	}

	public void setSupply(KaSupplier supply) {
		this.supply = supply;
	}

	@ExcelField(title="品类", align=2, sort=20)
	public String getKaCategoryName() {
		return kaCategory.getName();
	}
	
	public KaCategory getKaCategory() {
		return kaCategory;
	}

	public void setKaCategory(KaCategory kaCategory) {
		this.kaCategory = kaCategory;
	}
	@ExcelField(title="单位", align=2, sort=30)
	@Length(min=0, max=20, message="单位长度必须介于 0 和 20 之间")
	public String getUnit() {
		return "件";
	}

	public void setUnit(String unit) {
		this.unit = unit;
	}
	@ExcelField(title="期初库存", align=2, sort=40)
	public String getBeginNumForExport() {
		return beginNum==0.0?"":String.valueOf(beginNum);
	}
	
	@NotNull(message="期初库存不能为空")
	public Double getBeginNum() {
		return beginNum;
	}

	public void setBeginNum(Double beginNum) {
		this.beginNum = beginNum;
	}
	@ExcelField(title="单价", align=2, sort=50)
	public String getBeginPriceForExport() {
		DecimalFormat df2  = new DecimalFormat("###.00");//这样为保持2位 
		if(this.beginNum == 0.0 || "统计".equals(this.code))return "";
		else return String.valueOf(df2.format(this.beginCost/this.beginNum));
	}
	
	@NotNull(message="期初单价不能为空")
	public Double getBeginPrice() {
		if(this.beginNum == 0) return 0.0;
		return this.beginCost/this.beginNum;
	}

	public void setBeginPrice(Double beginPrice) {
		this.beginPrice = beginPrice;
	}
	
	@ExcelField(title="期初成本", align=2, sort=60)
	public String getBeginCostForExport() {
		return beginCost==0.0?"":String.valueOf(beginCost);
	}
	
	@NotNull(message="期初成本不能为空")
	public Double getBeginCost() {
		return beginCost;
	}

	public void setBeginCost(Double beginCost) {
		this.beginCost = beginCost;
	}
	
	@ExcelField(title="本期入库", align=2, sort=70)
	public String getCheckinNumForExport() {
		return checkinNum==0.0?"":String.valueOf(checkinNum);
	}
	
	public Double getCheckinNum() {
		return checkinNum;
	}

	public void setCheckinNum(Double checkinNum) {
		this.checkinNum = checkinNum;
	}
	
	public Double getCheckinPrice() {
		return checkinNum==0.0?0.0:checkinCost/checkinNum;
	}
	
	@ExcelField(title="采购单价", align=2, sort=80)
	public String getCheckinPriceForExport() {
		DecimalFormat df2  = new DecimalFormat("###.00");//这样为保持2位 
		if(this.checkinNum == 0.0 || "统计".equals(this.code))return "";
		else return String.valueOf(df2.format(this.checkinCost/this.checkinNum));
	}

	public void setCheckinPrice(Double checkinPrice) {
		this.checkinPrice = checkinPrice;
	}
	@ExcelField(title="采购成本", align=2, sort=90)
	public String getCheckinCostForExport() {
		return checkinCost==0.0?"":String.valueOf(checkinCost);
	}
	
	public Double getCheckinCost() {
		return checkinCost;
	}

	public void setCheckinCost(Double checkinCost) {
		this.checkinCost = checkinCost;
	}
	@ExcelField(title="数量", align=2, sort=100)
	public String getCheckoutNumForExport() {
		return checkoutNum==0.0?"":(String.valueOf(checkoutNum)+"("+String.valueOf(badNum)+")");
	}
	
	public double getCheckoutNum() {
		return checkoutNum;
	}

	public void setCheckoutNum(Double checkoutNum) {
		this.checkoutNum = checkoutNum;
	}
	public Double getCheckoutPrice() {
		return checkoutNum==0.0?0.0:checkoutCost/checkoutNum;
	}
	
	@ExcelField(title="单价", align=2, sort=110)
	public String getCheckoutPriceForExport() {
		DecimalFormat df2  = new DecimalFormat("###.00");//这样为保持2位 
		if(this.checkoutNum == 0.0 || "统计".equals(this.code))return "";
		else return String.valueOf(df2.format(this.checkoutCost/this.checkoutNum));
	}

	public void setCheckoutPrice(Double checkoutPrice) {
		this.checkoutPrice = checkoutPrice;
	}
	@ExcelField(title="出库成本", align=2, sort=120)
	public String getCheckoutCostForExport() {
		return checkoutCost==0.0?"":String.valueOf(checkoutCost);
	}
	
	public Double getCheckoutCost() {
		return checkoutCost;
	}

	public void setCheckoutCost(Double checkoutCost) {
		this.checkoutCost = checkoutCost;
	}
	@ExcelField(title="数量", align=2, sort=120)
	public String getEndNumForExport() {
		return endNum==0.0?"":String.valueOf(endNum);
	}
	public Double getEndNum() {
		return endNum;
	}

	public void setEndNum(Double endNum) {
		this.endNum = endNum;
	}
	
	public Double getEndPrice() {
		return endNum==0.0?0.0:endCost/endNum;
	}
	
	@ExcelField(title="单价", align=2, sort=130)
	public String getEndPriceForExport() {
		DecimalFormat df2  = new DecimalFormat("###.00");//这样为保持2位 
		if(this.endNum == 0.0 || "统计".equals(this.code))return "";
		else return String.valueOf(df2.format(this.endCost/this.endNum));
	}

	public void setEndPrice(Double endPrice) {
		this.endPrice = endPrice;
	}
	@ExcelField(title="成本", align=2, sort=140)
	public String getEndCostForExport() {
		return endCost==0.0?"":String.valueOf(endCost);
	}
	
	public Double getEndCost() {
		return endCost;
	}

	public void setEndCost(Double endCost) {
		this.endCost = endCost;
	}
	@ExcelField(title="货号", align=2, sort=10)
	@Length(min=1, max=64, message="货号长度必须介于 1 和 64 之间")
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}
	
	@Length(min=0, max=64, message="备注长度必须介于 0 和 64 之间")
	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}
	
	public Integer getSort() {
		return sort;
	}

	public void setSort(Integer sort) {
		this.sort = sort;
	}

	public Double getBadNum() {
		return badNum;
	}

	public void setBadNum(Double badNum) {
		this.badNum = badNum;
	}
	
}